/**
* ...
* @author Default
* @version 0.1
*/

package bdz.projects.slab.renderers{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import as3.common.ui.menu.core.MenuItem;
	import flash.text.*;
	import bdz.common.model.AppEnvironment;
	import flash.events.Event;
	import flash.utils.*;
	import as3.common.utils.*;
	import flash.text.StyleSheet;
	import flash.events.MouseEvent;
	import flash.net.*;
	public class ParagraphText extends MenuItem{
		
		private var virtualWidth:Number = 550;
		private var TextArea:TextField;
		private var virtualBG:MovieClip;
		private var vo:Object;
		private var extraButton:SimpleButton;
		private var settings:AppEnvironment;
		function ParagraphText(tstyle:Object,frm:TextFormat,sv:String=null){
			super(tstyle, frm, sv);
			settings = AppEnvironment.getEnv();
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		override protected function createField():void{
			TextArea = new TextField();
			TextArea.setTextFormat(textAreaFormat());
			TextArea.defaultTextFormat = textAreaFormat();
			setUpTArea(TextArea);
			TextArea.width = virtualWidth;
			addChild(TextArea);
			
			
		}
		private function initializeComponent(evt:Event):void{
			
			virtualBG = new MovieClip();
			super.createBounds(virtualBG, virtualWidth, 10, 0);
			addChild(virtualBG);
			setChildIndex(virtualBG, 0);
			if(vo.style){
				TextArea.styleSheet = vo.style;
			}
			TextArea.htmlText = vo.paragraph;
			
			if(vo.black){
				TextArea.textColor = 0x999999;
			}
			TextArea.alpha = 0;
			TweenLite.to(TextArea, .8, { alpha:1 } );
			cacheAsBitmap = true;
		}
		private function extraClick(evt:MouseEvent):void{
			navigateToURL(new URLRequest(settings.getSetting("baseURL")+vo.buttonLink.linkto), "_blank");
		}
		private function textAreaFormat():TextFormat{
			var menuFontFormat:TextFormat = new TextFormat();
			var fontObj:Object = getDefinitionByName("arial");
			menuFontFormat.color = 0x333333;
			menuFontFormat.leading = 4;
			menuFontFormat.kerning = 1;
			menuFontFormat.font = new fontObj().fontName;
			menuFontFormat.size = 10;
			return menuFontFormat;
		}
		private function setUpTArea(field:TextField):TextField{
			field.multiline = true;
			field.wordWrap = true;
			field.autoSize = "left";
			field.mouseWheelEnabled = false;
			field.antiAliasType = AntiAliasType.NORMAL;
			field.gridFitType = GridFitType.PIXEL;
			field.embedFonts = true;
			field.selectable = false;
			return field;
		}
		override public function get fieldWidth():Number{
			return virtualWidth;
		}
		override public function get fieldHeight():Number{
			return TextArea.height;
		}
		override public function set info(inf:*):void{
			vo = inf as Object;
		}
		override public function get info():*{
			return vo;
		}
	}
	
}